<template>
  <div class="mybox">
    <div class="top_box">
      <div class="item_box">
        <div class="title">{{ onebox.field_name }}</div>
        <div class="btm_value">
          <div class="value">{{ onebox.field_value }}</div>
          <div class="unit">{{ onebox.unit }}</div>
        </div>
      </div>
      <div class="item_box">
        <div class="title">{{ twobox.field_name }}</div>
        <div class="btm_value">
          <div class="value">{{ twobox.field_value }}</div>
          <div class="unit">{{ twobox.unit }}</div>
        </div>
      </div>
      <div class="item_box">
        <div class="title">{{ threebox.field_name }}</div>
        <div class="btm_value">
          <div class="value">{{ threebox.field_value }}</div>
          <div class="unit">{{ threebox.unit }}</div>
        </div>
      </div>
      <div class="item_box">
        <div class="title">{{ fourbox.field_name }}</div>
        <div class="btm_value">
          <div class="value">{{ fourbox.field_value }}</div>
          <div class="unit">{{ fourbox.unit }}</div>
        </div>
      </div>
    </div>
    <div class="top_title">每万人口健康医疗服务情况</div>
    <div class="chart" ref="main"></div>
  </div>
</template>
<script>
import { getAction, postAction } from '@/api/manage'
import * as echarts from 'echarts'
export default {
  name: '',
  data () {
    return {
      onebox: {},
      twobox: {},
      threebox: {},
      fourbox: {},
      nf: [],
      onedata: [],
      twodata: [],
      threedata: []
    }
  },
  mounted () {
    this.initData()
  },
  methods: {
    initData () {
      postAction('/topic/data/listAllData/dy_dp_msjc_jkyl_gk', {}).then(res => {
        if (res.success) {
          this.onebox = res.result.data[0]
          this.twobox = res.result.data[1]
          this.threebox = res.result.data[2]
          this.fourbox = res.result.data[3]
        }
      })
      postAction('/topic/data/listAllData/dy_dp_msjc_jkyl_wrjkylfw_year', {}).then(res => {
        if (res.success) {
          res.result.data.map(item => {
            this.onedata.push(item.bed_num)
            this.twodata.push(item.doctor_num)
            this.threedata.push(item.nurse_num)
            this.nf.push(item.year)
          })
          this.getChart(this.nf, this.onedata, this.twodata, this.threedata)
        }
      })
    },
    getChart (nf, onedata, twodata, threedata) {
      let myChart = echarts.init(this.$refs.main)
      let option

      option = {
        grid: {
          top: '20%',
          left: '3%',
          right: '2%',
          bottom: '2%',
          containLabel: true
        },
        legend: {
          // padding: [10, 0],
          orient: 'horizontal',
          right: 0,
          itemGap: 8,
          data: ['每万人口医生数', '每万人口护士数', '每万人口床位数'],
          textStyle: {
            color: '#f9f9f9',
            borderColor: '#fff',
            fontSize: 12
          }
        },
        xAxis: [{
          nameGap: 5,
          type: 'category',
          axisLine: {
            show: true,
            lineStyle: {
              color: '#999'
            }
          },
          axisLabel: {
            show: true,
            textStyle: {
              color: '#FFFFFF',
              fontSize: 10
            }
          },
          axisTick: {
            show: false
          },
          data: nf
        }],
        yAxis: [{
          name: '单位：人',
          type: 'value',
          nameTextStyle: {
            color: '#FFFFFF',
            fontSize: 12
          },
          min: 0,
          splitNumber: 5,
          splitLine: {
            show: true,
            lineStyle: {
              color: '#0a3256'
            }
          },
          axisLine: {
            show: false
          },
          axisLabel: {
            show: true,
            textStyle: {
              color: '#FFFFFF',
              fontSize: 10
            }
          },
          axisTick: {
            show: false
          }
        }],
        tooltip: {
          trigger: 'axis'
        },
        series: [{
          name: '每万人口医生数',
          type: 'line',
          symbolSize: 8, // 设置数据点的大小为10
          symbol: 'circle', // 设置数据点的形状为圆圈
          lineStyle: {
            color: '#55D297', // 线的颜色
            width: 2, // 线的宽度
            type: 'solid' // 线的类型，默认为实线
          },
          itemStyle: {
            color: '#55D297',
            borderColor: '#fff',
            borderWidth: 2 // 点的边框宽度
          },
          data: twodata
        },
        {
          name: '每万人口护士数',
          type: 'line',
          symbolSize: 8, // 设置数据点的大小为10
          symbol: 'circle', // 设置数据点的形状为圆圈
          lineStyle: {
            color: '#F3CD49', // 线的颜色
            width: 2, // 线的宽度
            type: 'solid' // 线的类型，默认为实线
          },
          itemStyle: {
            color: '#F3CD49',
            borderColor: '#fff',
            borderWidth: 2 // 点的边框宽度
          },
          data: threedata
        }, {
          name: '每万人口床位数',
          type: 'line',
          symbolSize: 8, // 设置数据点的大小为10
          symbol: 'circle', // 设置数据点的形状为圆圈
          lineStyle: {
            color: '#4390F7', // 线的颜色
            width: 2, // 线的宽度
            type: 'solid' // 线的类型，默认为实线
          },
          itemStyle: {
            color: '#4390F7',
            borderColor: '#fff',
            borderWidth: 2 // 点的边框宽度
          },
          data: onedata
        }
        ]
      }

      option && myChart.setOption(option)
    }
  }
}
</script>
<style lang="scss" scoped>
.mybox {
  .top_box {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;

    .item_box {
      width: 99px;
      height: 53px;
      background: url('./img/11.png')no-repeat center center;
      background-size: 100% 100%;

      .title {
        font-family: Source Han Sans CN;
        font-weight: bold;
        font-size: 18px;
        color: #F1F1F1;
        text-align: center;
        margin-bottom: 4px;
      }

      .btm_value {
        display: flex;
        justify-content: center;

        .value {
          font-family: Microsoft YaHei UI;
          font-weight: bold;
          font-size: 20px;
          color: #FFDE00;
        }

        .unit {
          font-family: Microsoft YaHei UI;
          font-weight: 400;
          font-size: 14px;
          color: #FFFFFF;
          margin-top: 5px;
        }
      }
    }

    .box {
      width: 150px;
      height: 53px;
      background: url('./img/11.png')no-repeat center center;
      background-size: 100% 100%;
    }
  }

  .top_title {
    width: 418px;
    height: 30px;
    background: url('./img/6.png')no-repeat;
    font-family: Microsoft YaHei UI;
    font-weight: bold;
    font-size: 16px;
    color: #FFFFFF;
    line-height: 30px;
    padding-left: 14px;
    margin-bottom: 10px;
  }

  .chart {
    width: 100%;
    height: 145px;
  }
}
</style>
